<template>
  <vxe-modal height="85vh" title="新增加计扣除鉴定信息" v-model="dialogVisible" width="80%" showFooter esc-closable show-zoom resize>
      <!-- 顶部搜索 -->
      <el-form :model="queryParams" ref="queryForm" size="small" v-show="showSearch" label-width="80px">
        <el-row :gutter="24">
          <el-col :span="6">
            <el-form-item label="项目名称:" prop="xmName">
              <el-input
                v-model="queryParams.xmName"
                placeholder="请输入项目名称"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="项目编号:" prop="xmBh">
              <el-input
                v-model="queryParams.xmBh"
                placeholder="请输入项目编号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <!-- 表格 -->
      <el-table @row-click="clickRow" ref="table"
                highlight-current-row :header-cell-style="{background:'#d0cece',color:'#000000',fontWeight:'bold'}"
                v-loading="loading" :data="jdjhList">
        <!--      <el-table-column type="selection" width="55" align="center"/>-->
        <el-table-column label="序号" align="center" type="index" :index="indexMethod"/>
        <el-table-column label="鉴定计划年度" align="center" prop="nd"/>
        <el-table-column label="项目名称" align="center" prop="xmName"/>
        <el-table-column label="项目编号" align="center" prop="xmBh"/>
        <el-table-column label="课题归属" align="center" prop="ktGs"/>
        <el-table-column label="项目总经费" align="center" prop="xmZjf"/>
        <el-table-column label="承担单位" align="center" prop="cdDw"/>
        <el-table-column label="是否可加计扣除" align="center" prop="sfKJjkc"/>
        <el-table-column label="项目负责人" align="center" prop="xmFzName"/>
        <el-table-column label="联系电话" align="center" prop="lxDh"/>
        <el-table-column label="当年发生额" align="center" prop="dnFse"/>
        <el-table-column label="起时间" align="center" prop="qTime"/>
        <el-table-column label="止时间" align="center" prop="zTime"/>
        <el-table-column label="自筹金额" align="center" prop="zcJe"/>
      </el-table>

      <!-- 分页组件 -->
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

    <div slot="footer" class="dialog-footer dialog-footer-center">
      <el-button size="small" @click="submitForm">
        <svg-icon icon-class="confirm1" class-name='custom-class' />确 定
      </el-button>
      <el-button size="small" @click="cancel">
        <svg-icon icon-class="cancel1" class-name='custom-class' />取 消
      </el-button>
    </div>


  </vxe-modal>
</template>

<script>
import {selectJdjhListByJjkcSq} from "@/api/jjkc/jdjh";

export default {
  name: "JjkcXmDx", //加计扣除项目单选
  inject: ['updateJjkcXmLabel'],
  data() {
    return {
      dialogVisible: false,// 是否显示弹出层
      // 显示搜索条件
      showSearch: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        xmsbId: null,
        nd: null,
        sfKJjkc: null,
        userId: null,
        deptId: null,
        xmName: null,
        xmBh: null,
        sfzSqLb: null,
      },
      loading: false,
      // 加计扣除鉴定计划表格数据
      jdjhList: [],
      // 总条数
      total: 0,
      selectedRow: null, // 保存当前选中的行
      jjkcXmLable: null,
      jdNd: null, //鉴定年度
    }
  },
  methods: {
    cancel() {
      this.dialogVisible = false;
    },
    submitForm(){
      this.updateJjkcXmLabel(this.jjkcXmLable);
      this.dialogVisible = false;
    },
    handleOpen(jdNd){
      this.jdNd = jdNd
      this.dialogVisible = true;
      this.getList();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 查询加计扣除鉴定计划列表 */
    getList() {
      this.loading = true;
      this.queryParams.nd = this.jdNd
      selectJdjhListByJjkcSq(this.queryParams).then(response => {
        this.jdjhList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 自定义序号 */
    indexMethod(index) {
      let pageNum = this.queryParams.pageNum - 1;
      if ((pageNum !== -1 && pageNum !== 0)) {
        return (index + 1) + (pageNum * this.queryParams.pageSize);
      } else {
        return (index + 1)
      }
    },
    clickRow(row) {
      this.selectedRow = row; // 更新选中的行
      this.jjkcXmLable = this.selectedRow
      const table = this.$refs.table;
      const selectedRows = table.selection;
      // 否则取消之前选中的行，并选中当前点击的行
      selectedRows.forEach(selectedRow => {
        table.toggleRowSelection(selectedRow);
      });
      table.toggleRowSelection(row);
    },

  }
}
</script>

<style scoped>

</style>
